﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Diagnostics;
using System.IO;

[assembly: log4net.Config.XmlConfigurator( ConfigFile="logging.config")]
[assembly: log4net.Config.Repository]
namespace MessageCallAspect.Aspect.Log
{
    public class Logger
    {
        readonly ILog log = LogManager.GetLogger("Logging");

        private static volatile Logger current;
        private static readonly object syncRoot = new object();

        private Logger()
        { }

        public static Logger Instance
        {
            get
            {
                if (current == null)
                {
                    lock (syncRoot)
                    {
                        if (current == null)
                        {
                            current = new Logger();
                        }
                    }
                }

                return current;
            }
        }

        public void Debug(string message)
        {
            if (this.log.IsDebugEnabled)
                this.log.Debug(string.Format("[{0}] {1}", DateTime.Now, message));
        }

        public void Info(string message)
        {
            if (this.log.IsInfoEnabled)
                this.log.Info(string.Format("[{0}] {1}", DateTime.Now, message));
        }

        public void Error(string message, Exception e)
        {
            if (this.log.IsErrorEnabled)
                this.log.Error(string.Format("[{0}] {1}", DateTime.Now, message), e);
        }

        public void Error(string message)
        {
            if (this.log.IsErrorEnabled)
                this.log.Error(string.Format("[{0}] {1}", DateTime.Now, message));
        }
    }

}
